Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds toast ID to toast api #3752

Merged
merged 6 commits into from
Apr 17, 2023

Conversation

ashwin-pc
Copy link
Member

@ashwin-pc ashwin-pc commented Mar 31, 2023

Description

Currently sending the same toast multiple times results in multiple toasts being rendered on the screen. This change allows the toast api to additionally accept an id parameter that

Before:
multiple toast

Now:
single toast

Issues Resolved

Check List

  • All tests pass
    • yarn test:jest
    • yarn test:jest_integration
    • yarn test:ftr
  • New functionality includes testing.
  • New functionality has been documented.
  • Update CHANGELOG.md
  • Commits are signed per the DCO using --signoff

Signed-off-by: Ashwin P Chandran <[email protected]>
@ashwin-pc ashwin-pc requested a review from a team as a code owner March 31, 2023 02:22
@ashwin-pc ashwin-pc self-assigned this Mar 31, 2023
Signed-off-by: Ashwin P Chandran <[email protected]>
@codecov-commenter
Copy link

codecov-commenter commented Mar 31, 2023

Codecov Report

Merging #3752 (92ccc30) into main (1edb195) will increase coverage by 0.01%.
The diff coverage is 50.00%.

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

@@            Coverage Diff             @@
##             main    #3752      +/-   ##
==========================================
+ Coverage   66.43%   66.45%   +0.01%     
==========================================
  Files        3209     3208       -1     
  Lines       61741    61752      +11     
  Branches     9537     9539       +2     
==========================================
+ Hits        41020    41035      +15     
+ Misses      18431    18429       -2     
+ Partials     2290     2288       -2     
Flag Coverage Δ
Linux 66.39% <50.00%> (+<0.01%) ⬆️
Windows 66.39% <50.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...uilder/public/application/components/workspace.tsx 6.25% <0.00%> (-0.21%) ⬇️
...public/application/utils/state_management/store.ts 18.75% <0.00%> (ø)
src/plugins/vis_builder/public/plugin.ts 22.44% <0.00%> (-0.47%) ⬇️
...rc/core/public/notifications/toasts/toasts_api.tsx 88.23% <100.00%> (+2.52%) ⬆️

... and 6 files with indirect coverage changes

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@@ -42,12 +42,10 @@ import { I18nStart } from '../../i18n';
/**
* Allowed fields for {@link ToastInput}.
*
* @remarks
* `id` cannot be specified.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we know the historical reason why?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I looked at the git history but as far as I can tell, there isn't a good reason. That's why I kept the default behavior as is. Only if you explicitly pass an id does the behavior change

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After reviewing, my understanding is that it was just intended to be an internal property, that simply auto-increments with each new toast. Ashwin's change here changes the purpose and usage of the property a bit (for example, passing string ids instead of a number), but not in a way that affects the historical usage. So I don't think it was intended as "specifying id is prohibited" and instead meant "specifying id is not necessary".

@joshuarrrr
Copy link
Member

@ashwin-pc I tried re-running the cypress tests, but you may want to take a look at why there are failed tests there.

@ashwin-pc
Copy link
Member Author

The branch was behind main by quite a bit. They should be passing now

src/core/public/notifications/toasts/toasts_api.tsx Outdated Show resolved Hide resolved
return existingToast;
}
}

const toast: Toast = {
id: String(this.idCounter++),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if it's somewhat surprising that we still increment the idCounter, but throw away the value. On the one hand, it means that the counter really does match the total number, but on the other, there are now some idCounter values that don't exist in the map of toast IDs.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We dont still increment, if an existing toast is found, we exit this function when we return the existing toast.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, I'm talking about the case where an id is provided, but there's no existing matching toast. In that case we increment, but don't use the incremented value.

@kavilla kavilla merged commit 14bde2b into opensearch-project:main Apr 17, 2023
opensearch-trigger-bot bot pushed a commit that referenced this pull request Apr 17, 2023
* Currently sending the same toast multiple times results in multiple toasts being rendered on the screen. This change allows the toast api to additionally accept an id parameter that
* Update changelog
* Update src/core/public/notifications/toasts/toasts_api.tsx

Issue Resolved:
#2643

Signed-off-by: Ashwin P Chandran <[email protected]>

Co-authored-by: Josh Romero <[email protected]>

---------

Signed-off-by: Ashwin P Chandran <[email protected]>
Co-authored-by: Sean Neumann <[email protected]>
Co-authored-by: Josh Romero <[email protected]>
(cherry picked from commit 14bde2b)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

# Conflicts:
#	CHANGELOG.md
ashwin-pc pushed a commit that referenced this pull request Apr 18, 2023
* Adds toast ID to toast api (#3752)

* Currently sending the same toast multiple times results in multiple toasts being rendered on the screen. This change allows the toast api to additionally accept an id parameter that
* Update changelog
* Update src/core/public/notifications/toasts/toasts_api.tsx

Issue Resolved:
#2643

Signed-off-by: Ashwin P Chandran <[email protected]>

Co-authored-by: Josh Romero <[email protected]>

---------

Signed-off-by: Ashwin P Chandran <[email protected]>
Co-authored-by: Sean Neumann <[email protected]>
Co-authored-by: Josh Romero <[email protected]>
(cherry picked from commit 14bde2b)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

# Conflicts:
#	CHANGELOG.md

* add changelog

Signed-off-by: Josh Romero <[email protected]>

---------

Signed-off-by: Josh Romero <[email protected]>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Josh Romero <[email protected]>
Co-authored-by: Anan Zhuang <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] [Vis Builder] Incorrect index pattern causes multiple errors
5 participants